<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui" xmlns:cc="http://java.sun.com/jsf/composite">
<cc:interface>
	<cc:attribute name="backingBean" type="br.com.felipeab.dexter.faces.CrudController" required="true" />
	<cc:attribute name="update" type="java.lang.String"
		shortDescription="Propriedade equivalente ao 'render' padrão. Porém é necessário alguns 
		cuidados para informar o ID do componente que deseja ser atualizado." />
	<cc:attribute name="showNew" type="java.lang.Boolean" default="true" />
	<cc:attribute name="showSave" type="java.lang.Boolean" default="true" />
	<cc:attribute name="showCancel" type="java.lang.Boolean" default="true" />
	<cc:attribute name="showSearch" type="java.lang.Boolean" default="true" />
	<cc:attribute name="showEdit" type="java.lang.Boolean" default="true" />
	<cc:attribute name="showDelete" type="java.lang.Boolean" default="true" />
	<cc:attribute name="msgConfirmSaving" type="java.lang.String" default="#{msgs['msg.question.saveRecord']}" />
</cc:interface>
<cc:implementation>
	<p:toolbar id="toolBarComponent" styleClass="toolBarCrud">
		<p:toolbarGroup>
			<p:commandButton id="btnNew" actionListener="#{cc.attrs.backingBean.newAction}" value="#{msgs['button.new']}"
				rendered="#{cc.attrs.showNew}" icon="ui-icon-document" disabled="#{cc.attrs.backingBean.disabledOnInsEdiSrch}"
				update="toolBarComponent btnNew #{cc.attrs.update}" process="@form" immediate="true" title="#{msgs['button.new']}"/>

			<p:commandButton id="btnSave" value="#{msgs['button.save']}" rendered="#{cc.attrs.showSave}" icon="ui-icon-disk"
				disabled="#{cc.attrs.backingBean.disableBtnSave}" update="msgPane btnPane" onclick="confirmCrudMenu.show();" title="#{msgs['button.save']}">
				<f:param name="msgConfirmation" value="#{cc.attrs.msgConfirmSaving}" />
				<f:param name="actionName" value="saveAction()" />
			</p:commandButton>

			<p:commandButton id="btnCancel" actionListener="#{cc.attrs.backingBean.cancelAction}" value="#{msgs['button.cancel']}"
				rendered="#{cc.attrs.showCancel}" icon="ui-icon-cancel" disabled="#{cc.attrs.backingBean.disabledOnDefault}"
				update="toolBarComponent btnCancel #{cc.attrs.update}" process="@form" immediate="true" title="#{msgs['button.cancel']}"/>

			<p:commandButton id="btnSearch" actionListener="#{cc.attrs.backingBean.searchAction}" value="#{msgs['button.search']}"
				rendered="#{cc.attrs.showSearch}" icon="ui-icon-search" disabled="#{cc.attrs.backingBean.disabledOnInsEdi}"
				update="toolBarComponent btnSearch #{cc.attrs.update}" process="@form" title="#{msgs['button.search']}"/>

			<p:commandButton id="btnEdit" actionListener="#{cc.attrs.backingBean.editAction}" value="#{msgs['button.edit']}"
				rendered="#{cc.attrs.showEdit}" icon="ui-icon-pencil" disabled="#{cc.attrs.backingBean.disableBtnEdit}"
				update="toolBarComponent btnEdit #{cc.attrs.update}" process="@form" title="#{msgs['button.edit']}"/>

			<p:commandButton id="btnDelete" actionListener="#{cc.attrs.backingBean.deleteAction}" value="#{msgs['button.delete']}"
				rendered="#{cc.attrs.showDelete}" icon="ui-icon-trash" disabled="#{cc.attrs.backingBean.disabledOnInsEdi}"
				update="toolBarComponent btnDelete #{cc.attrs.update}" process="@form" title="#{msgs['button.delete']}"/>
		</p:toolbarGroup>
	</p:toolbar>

	<p:dialog id="confirmCrudMenu" header="#{msgs['label.confirmation']}" widgetVar="confirmCrudMenu" modal="true" resizable="false"
		draggable="false" appendToBody="true">
		<h:panelGrid id="msgPane" columns="2">
			<h:graphicImage name="question.png" library="img" width="48" height="48" />
			<h:outputText value="#{param['msgConfirmation']}" />
		</h:panelGrid>
		<div align="center">
			<h:panelGrid id="btnPane" columns="2">
				<p:commandButton id="btnYes" value="#{msgs['button.yes']}" onclick="#{param['actionName']}; return false;" />
				<p:commandButton id="btnNo" value="#{msgs['button.no']}" onclick="confirmCrudMenu.hide();" />
			</h:panelGrid>
		</div>
	</p:dialog>
	<p:remoteCommand id="saveAction" name="saveAction" actionListener="#{cc.attrs.backingBean.saveAction}"
		oncomplete="confirmCrudMenu.hide();" process="@form" update="toolBarComponent btnSave #{cc.attrs.update}" />
</cc:implementation>
</html>